﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geodatabase;

namespace MyEngineExercise.我的扩展.其他
{
    /// <summary>
    /// 保存IField转换为DataTable时,所保存每个转换的信息，如字段类型,表类型，字段索引，对应转换成功的索引等
    /// </summary>
    public class FieldToDataTableInfo
    {
        /// <summary>
        /// 字段名
        /// </summary>
        private String _fieldName = String.Empty;
        /// <summary>
        /// 字段名
        /// </summary>
        public String FieldName { get { return _fieldName; } }


        /// <summary>
        /// 字段类型
        /// </summary>
        private esriFieldType _fieldType = esriFieldType.esriFieldTypeDouble;//默认是double
        /// <summary>
        /// 字段类型
        /// </summary>
        public esriFieldType FieldType { get { return _fieldType; } }



        /// <summary>
        /// 字段索引（对应转换陈功的表索引）
        /// </summary>
        private Int32 _fieldIndex = -1;
        /// <summary>
        /// 字段索引（对应转换陈功的表索引）
        /// </summary>
        public Int32 FieldIndex { get { return _fieldIndex; } }



        /// <summary>
        /// 表索引
        /// </summary>
        private Int32 _dataTableColumnIndex = -1;
        /// <summary>
        /// 表索引
        /// </summary>
        public Int32 DataTableIndex { get { return _dataTableColumnIndex; } }



        /// <summary>
        /// 表类型
        /// </summary>
        private Type _dataTableColumnType = typeof(Double);//默认是double
        /// <summary>
        /// 表类型
        /// </summary>
        public Type DataTableColumnType { get { return _dataTableColumnType; } }




        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="fieldName">字段名</param>
        /// <param name="fieldType">field类型</param>
        /// <param name="fieldIndex">DataTable索引</param>
        /// <param name="datatableIndex">field索引</param>
        public FieldToDataTableInfo(String fieldName, esriFieldType fieldType, Int32 dataTableColumnIndex, Int32 fieldIndex)
        {
            _fieldName = fieldName;
            _fieldType = fieldType;
            _fieldIndex = fieldIndex;

            _dataTableColumnIndex = dataTableColumnIndex;

            //根据fieldType，确定dataTable的类型
            switch (_fieldType)
            {
                case esriFieldType.esriFieldTypeDouble:
                    _dataTableColumnType = typeof(Double);
                    break;

                case esriFieldType.esriFieldTypeInteger:
                    _dataTableColumnType = typeof(Int32);
                    break;

                case esriFieldType.esriFieldTypeOID:
                    _dataTableColumnType = typeof(Int32);
                    break;

                case esriFieldType.esriFieldTypeSingle:
                    _dataTableColumnType = typeof(Double);
                    break;

                case esriFieldType.esriFieldTypeSmallInteger:
                    _dataTableColumnType = typeof(Int32);
                    break;

                case esriFieldType.esriFieldTypeString:
                    _dataTableColumnType = typeof(String);
                    break;

                default:
                    break;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="fieldType"></param>
        /// <param name="dataTableColumnIndex"></param>
        /// <param name="fieldIndex"></param>
        public FieldToDataTableInfo(String fieldName, Type dataTableColumnType, Int32 dataTableColumnIndex)
        {
            _fieldName = fieldName;
            _fieldIndex = -1;
            _dataTableColumnIndex = dataTableColumnIndex;
            _dataTableColumnType = dataTableColumnType;
        }
    }
}
